﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BOL;
using BOL.UI;
using UtilityExtensions;
using System.Web.UI.DataVisualization.Charting;
using System.Data.SqlClient;
using Website.Logger;
using System.Web.UI.HtmlControls;
using System.Drawing;

namespace UILGestion.VentaAdmin.Chart
{
    public partial class Chart08 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                if (!this.IsPostBack)
                {
                    idProyecto.Value = (string)Request.QueryString["idProyecto"];
                    FormatForm();
                }
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }
        }


        public void FormatForm()
        {



            



        }
       
         public void LoadChart(int idproyecto,int idBanco,int tipoUI)
        {

            var bol = new BOL.Ventas.OrdenVentaBL();

            var instalacionPeriodo = bol.GetOrdenVentaPendienteResumenMASTOTAL(idproyecto,
                                                                     idBanco,tipoUI).ToList();

            
            itemGridView.DataSource = instalacionPeriodo;
            itemGridView.DataBind();

        }

         protected void itemGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
         {
             //e.Row.Cells[0].BackColor = Color.FromName("#99CCFF");

             if (e.Row.RowType == DataControlRowType.DataRow)
             {

                 var item = (BOL.Ventas.OrdenVentaFormatoResumenInfo)(e.Row.DataItem);
                 bool esTotal = item.esTotal;


                 if (esTotal)
                 {
                     e.Row.BackColor = Color.LightYellow;
                     e.Row.Font.Bold = true;
                 }
                 if (item.idconcepto==4)
                 {
                     e.Row.BackColor = Color.LightGreen;
                     e.Row.Font.Bold = true;
                 }

                 e.Row.Cells[4].ForeColor = (item.hasta30 > 0) ? Color.Red : Color.Green;
                 e.Row.Cells[5].ForeColor = (item.hasta3060 > 0) ? Color.Red : Color.Green;
                 e.Row.Cells[6].ForeColor = (item.hasta60mas > 0) ? Color.Red : Color.Green;


             }
         }
    }
}